//
//  WeiboUserNode.m
//  yuikemall
//
//  Created by yuike5 yuike5 on 12-2-7.
//  Copyright (c) 2012年 yuike. All rights reserved.
//

#import "WeiboUserNode.h"

@implementation WeiboUserNode
@synthesize idx;
@synthesize screen_name;
@synthesize profile_image_url;
@synthesize domain; // 有可能为空啊。。。
@synthesize avatar_large;
@synthesize atName;
@synthesize atNameScreen;

-(int)gender
{
    if (isGirl)
        return GenderGIRL;
    if (isBoy)
        return GenderBOY;
    return GenderUNKNOW;
}


-(id) initWithSinaUser:(NSDictionary*)dict
{
    self = [super init];
    if (self) {
        self.idx = [[dict valueForKey:@"id"] longLongValue];
        self.screen_name = [dict valueForKey:@"screen_name"];
        self.profile_image_url = [dict valueForKey:@"profile_image_url"];
        self.domain = [dict valueForKey:@"domain"];
        self.avatar_large = [dict valueForKey:@"avatar_large"];
        //gender 	string 	性别，m：男、f：女、n：未知 
        NSString* gender = [dict valueForKey:@"gender"];
        isBoy = [@"m" compare:gender] == 0;
        isGirl = [@"f" compare:gender] == 0;
        
        self.atName = self.screen_name;
        self.atNameScreen = self.screen_name;
    }
    return self;
}

-(id) initWithQQ:(NSDictionary*)dict
{
    self = [super init];
    if (self) {
        self.idx = 0;
        self.screen_name = [dict valueForKey:@"nickname"];
        self.profile_image_url = [dict valueForKey:@"figureurl_1"];
        self.domain = [dict valueForKey:@"nickname"];
        self.avatar_large = [dict valueForKey:@"figureurl_2"];        
        // sex:用户性别，1-男，2-女，0-未填写
        NSString* sex = [dict valueForKey:@"gender"];
        isBoy = [@"男" compare:sex] == 0;
        isGirl = [@"女" compare:sex] == 0;        
        self.atName = self.domain;
        self.atNameScreen = self.screen_name;
    }
    return self;
}


-(id) initWithTencComment:(NSDictionary*)dict
{
    self = [super init];
    if (self) {
        self.idx = 0;
        self.screen_name = [dict valueForKey:@"nick"];
        self.profile_image_url = [[dict valueForKey:@"head"] stringByAppendingString:@"/50"];
        self.domain = [dict valueForKey:@"name"];
        self.avatar_large = [[dict valueForKey:@"head"] stringByAppendingString:@"/100"];
        
        // sex:用户性别，1-男，2-女，0-未填写
        int sex = [[dict valueForKey:@"sex"] intValue];
        isBoy = sex==1;
        isGirl = sex==2;
        
        self.atName = self.domain;
        self.atNameScreen = self.screen_name;
    }
    return self;
}

-(id) initWithTencWeibo:(NSDictionary*)dict
{
    self = [super init];
    if (self) {
        self.idx = 0;
        self.screen_name = [dict valueForKey:@"nick"];
        self.profile_image_url = [[dict valueForKey:@"head"] stringByAppendingString:@"/50"];
        self.domain = [dict valueForKey:@"name"];
        self.avatar_large = [[dict valueForKey:@"head"] stringByAppendingString:@"/100"];
        // sex:用户性别，1-男，2-女，0-未填写
        int sex = [[dict valueForKey:@"sex"] intValue];
        isBoy = sex==1;
        isGirl = sex==2;
        
        self.atName = self.domain;
        self.atNameScreen = self.screen_name;
    }
    return self;
}

-(id) initWithTencFriends:(NSDictionary*)dict
{
    self = [super init];
    if (self) {
        self.idx = 0;
        self.screen_name = [dict valueForKey:@"nick"];
        self.profile_image_url = [[dict valueForKey:@"headurl"] stringByAppendingString:@"/50"];
        self.domain = [dict valueForKey:@"name"];
        self.avatar_large = [[dict valueForKey:@"headurl"] stringByAppendingString:@"/100"];
        // sex:用户性别，1-男，2-女，0-未填写
        int sex = [[dict valueForKey:@"sex"] intValue];
        isBoy = sex==1;
        isGirl = sex==2;
        
        self.atName = self.domain;
        self.atNameScreen = self.screen_name;
    }
    return self;
}



-(NSString*) sinaDomain
{
    if (domain && [domain length] != 0) {
        return domain;
    }
    return [NSString stringWithFormat:@"%lld", idx];
}


-(void) dealloc
{
    [ screen_name release];
    [ profile_image_url release];
    [ domain release];
    [ avatar_large release];
    
    [atNameScreen release];
    
    
    [atName release];
    
    [super dealloc];
}

@end
